﻿Public Class StatusPoints

    Dim vPoints As Integer
    Dim vMoney As Integer
    Dim vTime As Integer = 0
    Dim TimeVar As String = "00:00:00"

    Dim UnlockStatus(1) As Boolean

    Dim LastLevel As Integer = 1

    Public Property Points() As Integer
        Get
            Return vPoints
        End Get
        Set(ByVal value As Integer)
            vPoints = value
            LabelPoints.Text = value
        End Set
    End Property

    Public Property Money() As Integer
        Get
            Return vMoney
        End Get
        Set(ByVal value As Integer)
            vMoney = value
            LabelMoney.Text = value

        End Set
    End Property

    Public Property Time() As Integer
        Get
            Return vTime
        End Get
        Set(ByVal value As Integer)
            vTime = value
            TimeVar = GetTime(value)
            LabelTime.Text = TimeVar
        End Set
    End Property

    Public Sub AddPoints(ByVal pts As Integer)
        Points += pts
    End Sub

    Public Sub IncreaseMoney(ByVal amt As Integer)
        Money += amt
    End Sub

    Public Sub DecreaseMoney(ByVal amt As Integer)
        Money -= amt
    End Sub

    Public Sub DecreaseLife()
        Parent.Controls.OfType(Of CowLife).ElementAtOrDefault(0).DecreaseLife()
    End Sub

    Private Sub RefreshValue()
        LabelMoney.Text = Money
        LabelPoints.Text = Points
    End Sub

    'Private Sub RefreshTime()
    '    Time = GetTime(TimeVar)
    'End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Time += 1
        CheckUnlocker()
        CheckLevel()
    End Sub

    Private Sub CheckLevel()
        If (LastLevel < 5) Then
            If (Points >= 1000 * LastLevel And LastLevel <= ParentForm.Tag) Then
                LevelUp()
            End If
        End If
    End Sub

    Private Sub CheckUnlocker()
        Dim Unlock(1) As Integer

        Dim obj As Shop = Parent.Controls.OfType(Of Shop).ElementAtOrDefault(0)

        Unlock(0) = 2000
        Unlock(1) = 5000

        If (Points >= Unlock(0) And unlockStatus(0) = False) Then
            ShowCongrats(0)
            unlockStatus(0) = True
            obj.UnlockFood(0)
        End If
        If (Points >= Unlock(1) And unlockStatus(1) = False) Then
            ShowCongrats(1)
            unlockStatus(1) = True
            obj.UnlockFood(1)
        End If
    End Sub

    Private Sub ShowCongrats(ByVal CongratsType As Integer)

        Dim Congrats As New CongratsMsg

        With Congrats
            .Left = 225
            .Top = 10
            .ShowByType(CongratsType)
        End With

        Parent.Controls.Add(Congrats)

    End Sub

    Public Sub Pause(ByVal val As Boolean)
        Timer1.Enabled = Not val
    End Sub

    Private Sub LabelLife_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("Points : " & Points)
    End Sub

    Private Function GetTime(ByVal Time As Integer)
        Dim result As String = "00:00:00"

        Dim sec As Integer
        Dim min As Integer
        Dim hrs As Integer

        sec = Time Mod 60
        min = ((Time - sec) / 60) Mod 60
        hrs = ((Time - (sec + (min * 60))) / 3600)

        result = GetTimeFormat(hrs) & ":" & GetTimeFormat(min) & ":" & GetTimeFormat(sec)

        Return result
    End Function

    Private Function GetTimeFormat(ByVal time As Integer)
        Dim result As String = "00"

        result = Format(time, "00")

        Return result
    End Function

    Public Sub LevelUp()
        ParentForm.Tag += 1
        LastLevel = ParentForm.Tag

        If (LastLevel = 2) Then
            ParentForm.Controls.OfType(Of CowLife).ElementAt(0).Life += 1
        End If

        PlayingRoom2.CreateCowAndHome(ParentForm.Tag)
        PlayingRoom2.PauseAll(True)
        Announcement.Show()
    End Sub

    Private Sub StatusPoints_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LastLevel = ParentForm.Tag
    End Sub
End Class